<template>
  <div>
    <FormPanel ref="fromCust" :list="formCustList" @formChange="changeCustHandle" :isSubmitBtn="false" :collapse="false" :labelWidth="130" :labelPosition="'top'"></FormPanel>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" :labelWidth="130" :labelPosition="'top'"> </FormPanel>
    <FilterTable
      ref="table"
      :columns="columns"
      :dataSource="tableList"
      height="auto"
      :onColumnsChange="(columns) => (this.columns = columns)"
      :onSummationChange="summationChange"
      :onRowSelectChange="selectChangeHandle"
    >
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" @click="addHandle()" icon="el-icon-plus">新 增</multiuse-button>
        <multiuse-button size="small" type="primary" @click="delHandle()" icon="el-icon-remove-outline">删 除</multiuse-button>
      </template>
    </FilterTable>
    <BaseDialog :visible.sync="isaddCar" :width="'80%'" :title="'选择车辆'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <addCar :orderData="orderData" @close="carcloseHandler" />
    </BaseDialog>
    <BaseDialog :visible.sync="isCustomer" title="大客户报备选择" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <searchCustomer :rowData="orderData" @close="customercloseHandler" />
    </BaseDialog>
    <BaseDialog
      :visible.sync="isCustomerDetail"
      :title="customerDetailType === 'follow' ? '大客户跟进信息' : '大客户报备信息'"
      destroyOnClose
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <customerDetail :type="customerDetailType" :rowData="bigCustomerData" @close="customerDetailcloseHandler" />
    </BaseDialog>
    <div style="height: 47px"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right',
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <multiuse-button type="primary" :click="closeDrawer.bind(this, 2)" :disabled="ischange">提 交</multiuse-button>
      <multiuse-button type="primary" :click="closeDrawer.bind(this, 3)" :disabled="ischange">保 存</multiuse-button>
    </div>
  </div>
</template>
<script>
import { getOrderDetailType, getAllDealerAddress, getSelfAddress, saveOrder, submitOrder } from '@/api/omSaleP/KeyCustomers/OrderSubmission/index.js';
import config from '@/assets/js/config';
import { IDNumber, phoneAndSolidify, phone, zipCode } from '@/utils/validate';
import { dictionary } from '@/utils/dictMixin';
import Cookies from 'js-cookie';
import addCar from './addCar';
import searchCustomer from './searchCustomer';
import customerDetail from './customerDetail';
import moment from 'moment';
export default {
  data() {
    this.saveData = null;
    this.saveCustData = null;
    return {
      formList: this.createdFrom(),
      formCustList: this.createdCustFrom(),
      columns: this.createdTable(),
      tableList: [],
      selectList: [],
      isaddCar: false,
      orderData: {},
      addressList: [],
      selfAddressList: [],
      addressSelectData: [],
      //自定义收车地址
      otherAddress: {
        address: '自定义',
        addressId: -1,
      },
      dealerCode: Cookies.get('ownerCode'),
      ischange: false,
      isCustomer: false,
      bigCustomerData: {},
      isCustomerDetail: false,
      customerDetailType: null,
    };
  },
  components: {
    addCar,
    searchCustomer,
    customerDetail,
  },
  // watch: {
  //   saveData: {
  //     handler: function (val) {
  //       console.log(val);
  //     },
  //   },
  // },
  created() {
    //初始化省份数据
    this.initProvince();
    //获取订单细分类型数据
    this.getOrderDetailType();
    //获取所有经销商收车地址
    this.getAllDealerAddress();
  },
  mounted() {
    this.table = this.$refs.table.$refs.pageTable;
  },
  mixins: [dictionary],
  methods: {
    //获取订单细分类型
    async getOrderDetailType() {
      let res = await getOrderDetailType({ isAvailable: 10041001 });
      // console.log('订单明细类型', res);
      if (res.resultCode == 200) {
        if (res.data.length > 0) {
          res.data.map((x) => {
            this.formList.find((item) => item.fieldName == 'orderDetailType').itemList.push({ text: x.subName, value: x.subId });
          });
          this.formList.find((item) => item.fieldName == 'orderDetailType').initialValue = res.data[0].subId;
        }
      }
    },
    // 获取收车地址
    async getAllDealerAddress() {
      let res1 = await getAllDealerAddress();
      let res2 = await getSelfAddress();
      if (res1.resultCode === 200) {
        this.addressList = res1.data;
        // this.addressList.unshift(this.otherAddress);
        // console.log('经销商收车地址:', this.addressList);
        //默认运输方式：运输
        if (this.addressList.length > 0) {
          let ininAddressId = this.addressList[0].addressId;
          this.formList.find((item) => item.fieldName === 'addressId').initialValue = ininAddressId;
          this.changTransportType(24091001);
          this.orderAddressOnChange(ininAddressId);
        }
      }
      if (res2.resultCode === 200) {
        this.selfAddressList = res2.data;
        // console.log('自提收车地址:', this.selfAddressList);
      }
    },
    //修改收车地址事件
    orderAddressOnChange(value) {
      //判断当前选中自提/运输
      let nowTransportType = this.formList.find((item) => item.fieldName === 'transportType').initialValue;
      this.formList.forEach((item) => {
        if (item.fieldName === 'linkPhone' || item.fieldName === 'linkMan') {
          item.disabled = true;
          item.rules = [];
        }
      });
      if (nowTransportType === 24091001) {
        //运输
        this.addressList.map((address) => {
          if (address.addressId === value) {
            this.formList.find((item) => item.fieldName === 'orderCity').initialValue = address.cityName;
            this.formList.find((item) => item.fieldName === 'linkMan').initialValue = address.linkMan;
            this.formList.find((item) => item.fieldName === 'linkPhone').initialValue = address.linkPhone;
            //判断是否为自定义地址
            // if (address.addressId == -1) {
            //   //打开地址相关输入编辑
            //   this.formList.find((item) => item.fieldName === 'orderCity').disabled = false;
            //   this.formList.find((item) => item.fieldName === 'linkMan').disabled = false;
            //   this.formList.find((item) => item.fieldName === 'linkPhone').disabled = false;
            //   //地址信息置空
            //   this.formList.find((item) => item.fieldName === 'orderCity').initialValue = '';
            //   this.formList.find((item) => item.fieldName === 'linkMan').initialValue = '';
            //   this.formList.find((item) => item.fieldName === 'linkPhone').initialValue = '';
            //   this.formList.forEach((item) => {
            //     if (item.fieldName === 'linkPhone' || item.fieldName === 'linkMan' || item.fieldName === 'orderCity') {
            //       item.rules = [{ required: true, message: '请输入', trigger: 'change' }];
            //     }
            //   });
            // } else {
            //   //关闭地址相关输入编辑
            //   this.formList.find((item) => item.fieldName === 'orderCity').disabled = true;
            //   this.formList.find((item) => item.fieldName === 'linkMan').disabled = true;
            //   this.formList.find((item) => item.fieldName === 'linkPhone').disabled = true;
            //   this.formList.forEach((item) => {
            //     if (item.fieldName === 'linkPhone' || item.fieldName === 'linkMan' || item.fieldName === 'orderCity') {
            //       item.rules = [];
            //     }
            //   });
            // }
          }
        });
      } else {
        //自提
        this.selfAddressList.map((address) => {
          if (address.addressId === value) {
            this.formList.find((item) => item.fieldName === 'orderCity').initialValue = '';
            this.formList.find((item) => item.fieldName === 'linkMan').initialValue = '';
            this.formList.find((item) => item.fieldName === 'linkPhone').initialValue = '';
          }
        });
        this.formList.forEach((item) => {
          if (item.fieldName === 'linkPhone' || item.fieldName === 'linkMan') {
            item.disabled = false;
            item.rules = [{ required: true, message: '请输入', trigger: 'change' }];
          }
        });
      }
      setTimeout(() => {
        this.$refs.from.$refs.form.clearValidate();
      }, 50);
    },
    //修改运输方式
    changTransportType(value) {
      let nowAddressList = [];
      if (value === 24091001) {
        //运输
        nowAddressList = this.addressList;
      } else {
        //自提
        nowAddressList = this.selfAddressList;
      }
      //重置收车地址下拉列表
      if (nowAddressList.length > 0) {
        // this.formList.find((item) => item.fieldName === 'addressId').itemList = nowAddressList.map((x) => ({
        //   text: `${x.address}`,
        //   value: x.addressId,
        // }));
        this.addressSelectData = nowAddressList.map((x) => ({
          text: `${x.address}`,
          value: x.addressId,
        }));
        let ininAddressId = nowAddressList[0].addressId;
        this.formList.find((item) => item.fieldName === 'addressId').initialValue = ininAddressId;
        //手动赋值
        this.formList.find((item) => item.fieldName === 'transportType').initialValue = value;
        this.orderAddressOnChange(ininAddressId);
      }
    },
    //初始化所在省份
    async initProvince() {
      let pl = await this.createRegionsList();
      this.formCustList.find((item) => item.fieldName == 'provinceId').itemList = pl;
    },
    //初始化所在市数据
    async initCity(provinceId) {
      //清空市
      this.clearFormItem(this.formCustList.find((item) => item.fieldName == 'cityId'));
      this.clearFormItem(this.formCustList.find((item) => item.fieldName == 'districtId'));
      if (!provinceId || provinceId == null || typeof provinceId == 'undefined') {
        return;
      }
      //取城市数据
      let rd = this.createcityList(provinceId);
      this.formCustList.find((item) => item.fieldName == 'cityId').itemList = rd;
    },
    // 获取区县
    async initRegion(regionId) {
      this.clearFormItem(this.formCustList.filter((x) => x.fieldName === 'districtId')[0]);
      if (!regionId) return;
      let rd = this.district(regionId);
      this.formCustList.find((item) => item.fieldName == 'districtId').itemList = rd;
    },
    // 清除
    clearFormItem(item) {
      item.initialValue = undefined;
      item.itemList = [];
    },
    // 选择车辆
    addHandle() {
      // this.$refs.fromCust.SUBMIT_FORM();
      // if (this.saveCustData) {
      //   this.$refs.from.SUBMIT_FORM();
      //   if (this.saveData) {
      //     let json = JSON.parse(JSON.stringify(this.saveData));
      //     json.dealerCode = this.dealerCode;
      //     this.orderData = json;
      //     this.isaddCar = true;
      //     this.saveData = null;
      //   }
      // }
      this.orderData = { dealerCode: this.dealerCode };
      this.isaddCar = true;
      this.saveData = null;
    },
    // 删除选中车辆
    async delHandle() {
      if (this.selectList.length === 0) {
        // 提示
        this.$notify({
          title: '警告',
          message: '请选择数据',
          type: 'warning',
        });
        return;
      }
      await this.$confirm('是否确定删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(async () => {
          this.selectList.forEach((data) => {
            this.table.EXECUTE_DELETE([data]);
            this.tableList = this.tableList.filter((item) => item !== data);
            //更新订单总金额
            this.calculateOrderTotalAmount();
          });
        })
        .catch(() => {});
    },
    //选中行
    selectChangeHandle(rows) {
      this.selectList = rows;
    },
    changeHandle(val) {
      this.saveData = val;
      this.saveCustData = this.$refs.fromCust.form;
    },
    changeCustHandle(val) {
      this.saveCustData = val;
    },
    //查询大客户报备信息
    seacherFun() {
      this.isCustomer = true;
    },
    customercloseHandler(val, data) {
      console.log('data', data);
      if (data) {
        this.bigCustomerData = data;
        this.formCustList.map(async (x) => {
          if (x.attachmentType) {
            data[x.fieldName].forEach((item) => {
              item.name = item.attachmentName;
              item.url = item.attachmentUrl;
              item.uid = item.attachmentUuid;
            });
          }
          if (data.provinceId) {
            await this.initCity(data.provinceId);
          }
          if (data.cityId) {
            await this.initRegion(data.cityId);
          }
          x.initialValue = data[x.fieldName];
        });
      }
      this.isCustomer = val;
    },
    //大客户报备/大客户需求信息查看
    editHandle(type) {
      if (type === 'demand') {
        this.customerDetailType = type;
        this.isCustomerDetail = true;
      } else if (type == 'follow') {
        this.customerDetailType = type;
        this.isCustomerDetail = true;
      }
    },
    customerDetailcloseHandler() {
      this.isCustomerDetail = false;
    },
    //订单操作
    async closeDrawer(type) {
      if (type == 1) {
        //关闭
        this.$emit('close');
      } else if (type == 2) {
        //提交
        const [err, formData] = await this.$refs.from.GET_FORM_DATA();
        if (err) {
          return;
        }
        let sumbitOrderData = this.buildSubmitorSaveData();
        if (sumbitOrderData) {
          await this.$confirm('是否确认提交大客户订单', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
          })
            .then(async () => {
              // console.log('提交数据', sumbitOrderData);
              this.ischange = true;
              let res = await submitOrder(sumbitOrderData);
              if (res.resultCode == 200) {
                this.$notify({
                  title: '成功',
                  message: '提交成功',
                  type: 'success',
                });
                this.$emit('close', sumbitOrderData);
              } else {
                this.saveData = null;
                this.ischange = false;
              }
            })
            .catch(() => {});
        }
      } else {
        //保存
        const [err, formData] = await this.$refs.from.GET_FORM_DATA();
        if (err) {
          return;
        }
        let saveOrderData = this.buildSubmitorSaveData();

        if (saveOrderData) {
          await this.$confirm('是否确认保存大客户订单', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
          })
            .then(async () => {
              // console.log('保存数据', saveOrderData);
              this.ischange = true;
              let res = await saveOrder(saveOrderData);
              if (res.resultCode == 200) {
                this.$notify({
                  title: '成功',
                  message: '保存成功',
                  type: 'success',
                });
                this.$emit('close', saveOrderData);
              } else {
                this.saveData = null;
                this.ischange = false;
              }
            })
            .catch(() => {});
        }
      }
    },
    //创建提交数据
    buildSubmitorSaveData() {
      this.$refs.fromCust.SUBMIT_FORM();
      if (this.saveCustData) {
        // console.log('大客户报备信息：', this.saveCustData);
        if (this.saveCustData.isBind !== 10041001) {
          this.$notify({
            title: '警告',
            message: '请在[大客户报备]菜单绑定SAP客户编号后绑定SAP后再进行大客户订单操作',
            type: 'warning',
          });
          return;
        }

        this.$refs.from.SUBMIT_FORM();
        if (this.saveData) {
          // console.log('大客户订单信息：', this.saveData);
          if (this.tableList.length < 1) {
            this.$notify({
              title: '警告',
              message: '请选择车辆',
              type: 'warning',
            });
            return;
          }
          let orderDetail = this.tableList;
          let checkOrderNum1 = false;
          let checkOrderNum2 = false;
          let checkafterDiscountAmount1 = false;
          let checkafterDiscountAmount2 = false;
          orderDetail.map((x) => {
            let checkNum = this.checkNumOrPrices(1, x.orderNum);
            let checkPrices = this.checkNumOrPrices(2, x.afterDiscountAmount);
            //数量校验
            if (!x.orderNum || !checkNum) {
              checkOrderNum1 = true;
            }
            if (Number(x.orderNum) > 10000000000 || Number(x.orderNum) < 1) {
              checkOrderNum2 = true;
            }
            //采购价格校验
            if (!x.afterDiscountAmount || !checkPrices) {
              checkafterDiscountAmount1 = true;
            }
            if (Number(x.afterDiscountAmount) > 10000000000 || Number(x.afterDiscountAmount) <= 0) {
              checkafterDiscountAmount2 = true;
            }
          });
          if (checkOrderNum1) {
            this.$notify({
              title: '警告',
              message: '提报数量为空或格式不正确',
              type: 'warning',
            });
            return;
          }
          if (checkOrderNum2) {
            this.$notify({
              title: '警告',
              message: '输入数量过大或过小',
              type: 'warning',
            });
            return;
          }
          if (checkafterDiscountAmount1) {
            this.$notify({
              title: '警告',
              message: '采购价格金额为空或格式不正确',
              type: 'warning',
            });
            return;
          }
          if (checkafterDiscountAmount2) {
            this.$notify({
              title: '警告',
              message: '采购价格填入金额过大或过小',
              type: 'warning',
            });
            return;
          }
          let json = JSON.parse(JSON.stringify(this.saveData));
          let customerData = JSON.parse(JSON.stringify(this.saveCustData));
          this.formCustList.map(async (x) => {
            //附件数据转换
            if (x.attachmentType) {
              customerData[x.fieldName].forEach((item) => {
                item.attachmentName = item.name;
                item.attachmentUrl = item.url;
                item.attachmentUuid = item.uid;
                item.attachmentType = x.attachmentType;
              });
            }
          });
          customerData.id = this.bigCustomerData.id;
          if (json.uploadFileData.length > 0) {
            json.attachmentUrl = json.uploadFileData[0].url;
            json.attachmentName = json.uploadFileData[0].name;
          }
          let addressData = [];
          //判断运输方式：自提/运输
          if (json.transportType === 24091001) {
            addressData = this.addressList;
          } else {
            addressData = this.selfAddressList;
          }
          if (addressData.length > 0) {
            let nowAddress = addressData.find((x) => x.addressId == json.addressId);
            if (nowAddress) {
              json.orderAddress = nowAddress.address;
            }
          }
          json.orderYear = json.orderYearMonth.split('-')[0];
          json.orderMonth = json.orderYearMonth.split('-')[1];
          json.isOemCreated = 10041001;
          json.bigCustomerDTO = customerData;
          json.detailDTOList = orderDetail;
          console.log('创建数据', json);
          return json;
        }
      }
    },
    async carcloseHandler(carList, orderData) {
      this.isaddCar = false;
      this.saveData = null;
      // console.log(carList, '选择车辆');
      if (carList != undefined && carList.length > 0) {
        carList.forEach((car) => {
          // 提报数量
          car.orderNum = 1;
          // 车辆用途：默认客户订购
          car.vehicleUse = 21021001;
          // 市场指导价
          car.singleAmount = car.oemDirectivePrice;
          //后台实体保持一致
          car.packageName = car.configName;
          car.packageCode = car.configCode;
          car.trimId = car.trimColorId;
          car.trimCode = car.trimColor;
          car.trimName = car.trimColorName;
          this.table.EXECUTE_INSERT([car]);
        });
      }
    },
    //订单总金额计算
    calculateOrderTotalAmount() {
      let orderTotalAmount = 0;
      this.tableList.map((x) => {
        let checkNum = this.checkNumOrPrices(1, x.orderNum);
        let checkPrices = this.checkNumOrPrices(2, x.afterDiscountAmount);
        if (checkNum && checkPrices) {
          orderTotalAmount = orderTotalAmount + Number(x.orderNum) * Number(x.afterDiscountAmount);
        }
      });
      this.formList.find((item) => item.fieldName == 'orderTotalAmount').initialValue = Number(orderTotalAmount).toFixed(2);
    },
    //改变数量
    changeNum(index, data) {
      // console.log(index, data, '改变数量');
      let num = '';
      let str = '';
      for (let i in index) {
        num = index[i];
        str = i.split('|')[0];
      }
      if (num > 10000000000) {
        this.$notify({
          title: '警告',
          message: '输入数量过大',
          type: 'warning',
        });
        return;
      }
    },
    //改变采购价格
    changeAfterDiscountAmount(index, data) {
      // console.log(index, data, '改变采购价格');
      let afterDiscountAmount = '';
      let str = '';
      for (let i in index) {
        afterDiscountAmount = index[i];
        str = i.split('|')[0];
      }
      if (afterDiscountAmount > 10000000000) {
        this.$notify({
          title: '警告',
          message: '输入采购价格金额过大',
          type: 'warning',
        });
        return;
      }
    },
    //数量或价格数据格式校验
    checkNumOrPrices(type, value) {
      let check = false;
      let numRep = /^[1-9]\d*$/;
      let pricesRep = /^[1-9]\d*(\.\d{0,2})?$/;
      if (type == 1) {
        //数量校验
        if (numRep.test(value)) {
          check = true;
        }
        return check;
      } else {
        //价格校验
        if (pricesRep.test(value)) {
          check = true;
        }
        return check;
      }
    },
    //数据校验
    checkValueNum(a) {
      if (!a || a == null || isNaN(a)) {
        return 0;
      } else {
        return a;
      }
    },
    summationChange(data) {
      // console.log('---合计---',data);
    },
    formatNumber(val) {
      return Number(val).toFixed(2);
    },
    createdCustFrom() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '大客户报备信息',
        },
        {
          type: 'INPUT',
          label: '大客户编号',
          fieldName: 'customersNo',
          placeholder: '请选择',
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
              </div>
            );
          },
        },
        {
          type: 'SELECT',
          label: '大客户来源',
          fieldName: 'customersType',
          disabled: true,
          initialValue: 21081001,
          itemList: this.createDictList('2108'),
        },
        {
          type: 'SELECT',
          label: '大客户类型',
          disabled: true,
          fieldName: 'customerType',
          initialValue: 21171002,
          itemList: this.createDictList('2117'),
        },
        {
          type: 'INPUT',
          label: '大客户名称',
          disabled: true,
          fieldName: 'customersName',
        },
        {
          type: 'INPUT',
          label: '运营单位联系人',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
          fieldName: 'contactsName',
        },
        {
          type: 'INPUT',
          label: '运营单位联系电话',
          rules: [
            { required: true, message: '请输入', trigger: 'blur' },
            { message: '请输入正确的手机号', validator: phone, trigger: 'blur' },
          ],
          fieldName: 'customerPhone',
        },
        {
          type: 'SELECT',
          label: '省份',
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          fieldName: 'provinceId',
          initialValue: '',
          placeholder: '',
          itemList: [],
          change: (val) => {
            this.initCity(val);
          },
        },
        {
          type: 'SELECT',
          label: '城市',
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          fieldName: 'cityId',
          initialValue: '',
          placeholder: '',
          itemList: [],
          change: (val) => {
            this.initRegion(val);
          },
        },
        {
          type: 'SELECT',
          label: '县区',
          fieldName: 'districtId',
          placeholder: '',
          initialValue: '',
          itemList: [],
        },
        {
          type: 'INPUT',
          label: '联系地址',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
          maxlength: 36,
          fieldName: 'addressName',
          placeholder: '',
        },
        {
          type: 'SELECT',
          label: '证件类型',
          fieldName: 'credentialsType',
          disabled: true,
          initialValue: 21201008,
          itemList: this.createDictList('2120'),
        },
        {
          type: 'INPUT',
          label: '证件号',
          disabled: true,
          required: true,
          fieldName: 'credentialsNo',
        },
        {
          type: 'INPUT',
          label: '法人代表姓名',
          fieldName: 'legalPersonName',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
        },
        {
          type: 'INPUT',
          label: '法人身份证号',
          fieldName: 'legalPersonIdCard',
          rules: [
            { required: true, message: '请输入', trigger: 'blur' },
            { message: '请输入正确的身份证号', validator: IDNumber, trigger: 'blur' },
          ],
        },
        {
          type: 'INPUT',
          label: '法人代表手机',
          fieldName: 'legalPersonMobile',
          rules: [
            { required: true, message: '请输入', trigger: 'blur' },
            { message: '请输入正确的手机号', validator: phone, trigger: 'blur' },
          ],
        },
        {
          type: 'INPUT',
          label: '授权人身份证号',
          fieldName: 'authorizationPersonIdCard',
          rules: [
            { required: true, message: '请输入', trigger: 'blur' },
            { message: '请输入正确的身份证号', validator: IDNumber, trigger: 'blur' },
          ],
        },
        {
          type: 'INPUT',
          label: '传真',
          maxlength: 36,
          fieldName: 'fax',
          placeholder: '',
        },
        {
          type: 'INPUT',
          label: '邮编',
          maxlength: 36,
          rules: [{ message: '请输入正确的邮编', validator: zipCode, trigger: 'blur' }],
          fieldName: 'zipCode',
          placeholder: '',
        },
        {
          type: 'INPUT',
          label: 'SAP客户编号',
          disabled: true,
          fieldName: 'sapCustomersNo',
        },
        {
          type: 'SELECT',
          label: '是否绑定SAP客户编号',
          fieldName: 'isBind',
          disabled: true,
          placeholder: '',
          itemList: this.createDictList('1004'),
          offsetRightCols: 1,
        },
        {
          type: 'BREAK_SPACE',
          label: '',
        },
        {
          type: 'UPLOAD_FILE',
          label: '法人身份证正面',
          fieldName: 'legalPersonIdCodeFrontList',
          placeholder: '请上传法人身份证正面',
          attachmentType: 11131001,
          selfCols: 1,
          initialValue: [],
          rules: [{ required: true, message: '请上传法人身份证正面', trigger: 'change' }],
          upload: {
            actionUrl: `${config.uploadUrl}/api/file/oss/upload`,
            fixedSize: [5, 3],
            limit: 1,
            isCalcHeight: true,
          },
        },
        {
          type: 'UPLOAD_FILE',
          label: '法人身份证反面',
          fieldName: 'legalPersonIdCodeReverseList',
          attachmentType: 11131002,
          placeholder: '请上传法人身份证反面',
          selfCols: 1,
          initialValue: [],
          rules: [{ required: true, message: '请上传法人身份证反面', trigger: 'change' }],
          upload: {
            actionUrl: `${config.uploadUrl}/api/file/oss/upload`,
            fixedSize: [5, 3],
            limit: 1,
            isCalcHeight: true,
          },
        },
        {
          type: 'UPLOAD_FILE',
          label: '管理员授权文件',
          attachmentType: 11131003,
          fieldName: 'administratorAuthorizationFileList',
          placeholder: '请上传管理员授权文件',
          selfCols: 1,
          initialValue: [],
          rules: [{ required: true, message: '请上传管理员授权文件', trigger: 'change' }],
          upload: {
            actionUrl: `${config.uploadUrl}/api/file/oss/upload`,
            fixedSize: [5, 3],
            limit: 1,
            isCalcHeight: true,
          },
        },
        {
          type: 'UPLOAD_FILE',
          label: '授权人身份证正面',
          attachmentType: 11131004,
          fieldName: 'authorizationIdCardFrontList',
          placeholder: '请上传授权人身份证正面',
          selfCols: 1,
          initialValue: [],
          rules: [{ required: true, message: '请上传授权人身份证正面', trigger: 'change' }],
          upload: {
            actionUrl: `${config.uploadUrl}/api/file/oss/upload`,
            fixedSize: [5, 3],
            limit: 1,
            isCalcHeight: true,
          },
        },
        {
          type: 'UPLOAD_FILE',
          label: '授权人身份证反面',
          attachmentType: 11131005,
          fieldName: 'authorizationIdCardReverseList',
          placeholder: '请上传授权人身份证反面',
          selfCols: 1,
          initialValue: [],
          rules: [{ required: true, message: '请上传授权人身份证反面', trigger: 'change' }],
          upload: {
            actionUrl: `${config.uploadUrl}/api/file/oss/upload`,
            fixedSize: [5, 3],
            limit: 1,
            isCalcHeight: true,
          },
        },
        {
          type: 'UPLOAD_FILE',
          label: '营业执照',
          fieldName: 'businessLicenseList',
          attachmentType: 11131006,
          placeholder: '请上传营业执照',
          selfCols: 1,
          initialValue: [],
          rules: [{ required: true, message: '请上传营业执照', trigger: 'change' }],
          upload: {
            actionUrl: `${config.uploadUrl}/api/file/oss/upload`,
            fixedSize: [5, 3],
            limit: 1,
            isCalcHeight: true,
          },
        },
        {
          type: 'INPUT',
          label: '需求信息',
          render: () => {
            return (
              <multiuse-button size="mini" type="text" onClick={() => this.editHandle('demand')}>
                查看
              </multiuse-button>
            );
          },
        },
        {
          type: 'INPUT',
          label: '跟进信息',
          render: () => {
            return (
              <multiuse-button size="mini" type="text" onClick={() => this.editHandle('follow')}>
                查看
              </multiuse-button>
            );
          },
        },
      ];
    },
    createdFrom() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '大客户订单信息',
        },
        {
          type: 'INPUT',
          label: '订单编号',
          fieldName: 'orderNo',
          disabled: true,
        },
        {
          type: 'DATE',
          label: '订单年月',
          fieldName: 'orderYearMonth',
          dateType: 'month',
          initialValue: moment().format('YYYY-MM'),
          disabled: true,
        },
        {
          type: 'SELECT',
          label: '订单类型',
          fieldName: 'orderType',
          disabled: true,
          initialValue: 21051004,
          itemList: this.createDictList('2105').filter((item) => item.value == '21051004'),
        },
        {
          type: 'SELECT',
          label: '订单细分类型',
          fieldName: 'orderDetailType',
          itemList: [],
          disabled: true,
        },
        {
          type: 'SELECT',
          label: '订单状态',
          fieldName: 'orderStatus',
          placeholder: '请选择',
          itemList: this.createDictList('2104'),
          disabled: true,
          initialValue: 21041001,
        },
        {
          type: 'SELECT',
          label: '紧急度',
          fieldName: 'emergencyType',
          placeholder: '请选择',
          itemList: this.createDictList('2101'),
          initialValue: 21011001,
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
        },
        {
          type: 'SELECT',
          label: '运输方式',
          fieldName: 'transportType',
          placeholder: '请选择',
          itemList: this.createDictList('2409'),
          initialValue: 24091001,
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          change: (value) => {
            this.changTransportType(value);
          },
        },
        // {
        //   type: 'SELECT',
        //   label: '收车地址',
        //   fieldName: 'addressId',
        //   placeholder: '请选择',
        //   rules: [{ required: true, message: '请选择', trigger: 'change' }],
        //   editType: 'select',
        //   editable: true,
        //   itemList: [],
        //   change: (value) => {
        //     this.orderAddressOnChange(value);
        //   },
        // },
        {
          type: 'INPUT',
          label: '收车地址',
          fieldName: 'addressId',
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          render: () => {
            return (
              <el-select
                size="mini"
                v-model={this.formList.find((item) => item.fieldName === 'addressId').initialValue}
                filterable
                placeholder="请选择"
                onChange={(value) => {
                  this.formList.find((item) => item.fieldName === 'addressId').initialValue = value;
                  this.orderAddressOnChange(value);
                }}
              >
                {this.addressSelectData.map((item) => (
                  <el-option key={item.value} label={item.text} value={item.value} />
                ))}
              </el-select>
            );
          },
        },
        {
          type: 'INPUT',
          label: '送达城市',
          fieldName: 'orderCity',
          disabled: true,
          placeholder: '请输入',
          rules: [],
        },
        {
          type: 'INPUT',
          label: '联系人',
          fieldName: 'linkMan',
          disabled: true,
          placeholder: '请输入',
          rules: [],
        },
        {
          type: 'INPUT',
          label: '联系电话',
          fieldName: 'linkPhone',
          disabled: true,
          placeholder: '请输入',
          rules: [],
        },
        {
          type: 'SELECT',
          label: '开票类型',
          fieldName: 'invoiceType',
          itemList: this.createDictList('2107'),
          placeholder: '请选择',
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
        },
        {
          type: 'INPUT',
          label: '订单总金额',
          fieldName: 'orderTotalAmount',
          numberFormat: true,
          disabled: true,
        },
        {
          type: 'UPLOAD_FILE',
          label: '附件上传',
          fieldName: 'uploadFileData',
          initialValue: [],
          upload: {
            actionUrl: `${config.uploadUrl}/api/file/oss/upload`,
            limit: 1,
            fileSize: 20,
          },
          selfCols: 3,
        },
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        {
          title: '物料编码',
          dataIndex: 'productCode',
          sorter: true,
          filter: true,
          width: 200,
          filterType: 'input',
        },
        {
          title: '物料描述',
          dataIndex: 'productName',
          sorter: true,
          filter: true,
          width: 400,
          filterType: 'input',
        },
        {
          title: '提报数量',
          dataIndex: 'orderNum',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: 100,
          editable: true,
          editType: 'number',
          editRequired: true,
          defaultEditable: true,
          editPattern: /^[1-9]\d*$/,
          summation: true,
          onInput: (index, data) => {
            this.changeNum(index, data);
            this.calculateOrderTotalAmount();
          },
        },
        {
          title: '车辆用途',
          dataIndex: 'vehicleUse',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'select',
          editRequired: true,
          render: (p) => {
            return (
              <el-select
                size="mini"
                v-model={p.row.vehicleUse}
                disabled
                onChange={(value) => {
                  p.row.vehicleUse = value;
                }}
              >
                {this.createDictList('2102').map((item) => (
                  <el-option key={item.value} label={item.text} value={item.value} />
                ))}
              </el-select>
            );
          },
        },
        {
          title: '采购价格',
          dataIndex: 'afterDiscountAmount',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: 120,
          editable: true,
          editType: 'number',
          editRequired: true,
          defaultEditable: true,
          editPattern: /^[1-9]\d*(\.\d{0,2})?$/,
          summation: true,
          onInput: (index, data) => {
            this.changeAfterDiscountAmount(index, data);
            this.calculateOrderTotalAmount();
          },
        },
        {
          title: '市场指导价',
          dataIndex: 'singleAmount',
          sorter: true,
          filter: true,
          precision: 2,
          numberFormat: true,
          align: 'right',
          filterType: 'input',
        },
        {
          title: '车系',
          dataIndex: 'seriesName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '车型',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '配置',
          dataIndex: 'configName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '选装',
          dataIndex: 'optionName',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '内饰',
          dataIndex: 'trimName',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '外饰',
          dataIndex: 'colorName',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
      ];
    },
  },
};
</script>
<style lang="less">
.discount {
  text-decoration: underline;
  color: #d1291a;
  cursor: pointer;
}
.upload-btn {
  width: 100%;
}
.el-upload-list__item-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  padding-right: 20px;
  box-sizing: border-box;
}
</style>
